#include "stdafx.h"

#include "Game.h"

namespace ETM
{
	Game::Game() :
		input(window.GetInput())
	{
		
	}

	void Game::Run()
	{
		Initialize();

		Load();

		while(window.IsOpened())
		{
			sf::Event Event;
			while(window.GetEvent(Event))
			{
				if(Event.Type == sf::Event::Closed)
					window.Close();
			}

			Update();

			Render();
		}
	}

	void Game::Initialize()
	{
		window.Create(sf::VideoMode(800, 600, 32), "Escape the Mine");
		window.SetFramerateLimit(60);
		window.UseVerticalSync(true);
	}

	void Game::Load()
	{
		screenManager.AddScreen(new MainMenuScreen());
	}

	void Game::Update()
	{
		if(!screenManager.IsRunning())
			Exit();

		Input::SetCurrentState(input);

		screenManager.Update(window.GetFrameTime());

		Input::SetPreviousState(input);
	}

	void Game::Render()
	{
		window.Clear();

		screenManager.Render(window);

		window.Display();
	}

	void Game::Exit()
	{
		window.Close();
	}
}